package com.truongnha.clienttn.presentation.temp;

import java.util.List;

import org.apache.http.cookie.Cookie;


import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.preference.PreferenceManager;

public class CookieManager {
	public static void saveCookies(Context context , List<Cookie> cookies){
		String cookiesString = CookieFactory.stringFromCookies(cookies);
		SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
		Editor edit = preferences.edit();
		if (!cookiesString.equals("")) {
			edit.putString("cString", cookiesString);
			edit.putBoolean("saved", true);
			MyLog.show(cookiesString);
		}
		edit.commit(); 
		
	}
	public static boolean isSaved(Context context){
		SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
		boolean saved = preferences.getBoolean("saved", false);
		return saved;
	}
	public static List<Cookie> getCookies(Context context ){
		SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
		String cookiesString = preferences.getString("cString", "");
		MyLog.show(cookiesString);
		return CookieFactory.loadCookiesFromString(cookiesString);
	}
	public static void clear(Context context){
		SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
		Editor edit = preferences.edit();
		edit.putString("cString", "");
		edit.putBoolean("saved", false);
		edit.commit(); 		
	}
}
